home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / arexx / rxdssppr.lha / rexxdossupport / rexx / RxDS_test.rexx
OS/2 REXX Batch file  |  1996-02-23  |  5KB  |  162 lines

  1. /* RxDS_test.rexx --- test for RexxDosSupport.library
  2. * $Id: RxDS_test.rexx,v 1.2 1996/02/23 12:42:18 hartmut Exp $
  3. */
  4.  
  5. call addlib("rexxdossupport.library",0,-30, 3)
  6.  
  7. parse source . . . file .
  8. say "Let's get the filename and path of this script" file
  9. fp = FilePart(file);
  10. say "FilePart:" fp
  11. say "PathPart:" PathPart(file);
  12. say "AbsolutePath("fp"):" AbsolutePath("RxDS_test.rexx")
  13.  
  14. say; say "some tests about AddPart()"
  15.  
  16. call TestAddPart("Oberon:bla/fasel/foo","Bang:oha!")
  17. call TestAddPart("Oberon:bla/fasel/foo",":oha!")
  18. call TestAddPart("Oberon:bla/fasel/foo","oha/aha!")
  19. call TestAddPart("Oberon:bla/fasel/foo","/oha/aha!")
  20. call TestAddPart("Oberon:bla/fasel/foo","//oha//aha!")
  21. call TestAddPart("Oberon:LibLink/Mathe","//Mymods/txt")
  22. /*call TestAddPart("Oberon:"Copies('a',560),"//Mymods/txt")*/
  23.  
  24. say; say "Now we play with directories"
  25. if ~ MakeDir("ram:foo") then say fault(rc, "test");
  26. if ~ Rename("ram:foo","ram:bar") then say fault(rc, "test");
  27. if ~ SetComment("ram:bar","stupit comment") then say fault(rc, "test");
  28. if ~ SetProtection("ram:bar",'00000000'x) then say fault(rc, "test");
  29. if ~ Delete("ram:bar") then say fault(rc, "test");
  30.  
  31. say; say "Generate some error messages:"
  32. text = fault(0,"test"); if rc = 0 then say text
  33. text = fault(215,"test"); if rc = 0 then say text
  34. text = fault(215); if rc = 0 then say text
  35.  
  36. say; say "The most interesting feature: ReadArgs() :-))"
  37. server = 'default'
  38. template = "name/A,,passwd,server/K,prio/N"
  39. input = "hartmut foobar prio 10"
  40.  
  41. if ReadArgs(input,template) then
  42.   say args.name '--' args.passwd '--' args.server '--' args.prio
  43.   say name '--' passwd '--' server '--' prio
  44. if ReadArgs(input,template,"args.") then
  45.   say args.name '--' args.passwd '--' args.server '--' args.prio
  46.  
  47. say "here as error message has to appear:"
  48. if ~ ReadArgs("server=default", template, "args.") then
  49.   say Fault(rc,"test")
  50.  
  51. /*--- tests for /T ---*/
  52. drop test
  53. call ReadArgs("", "test/T")
  54. say test
  55.  
  56. test = 1;
  57. call ReadArgs("", "test/T")
  58. say test
  59.  
  60. call ReadArgs("test=No", "test/T")
  61. say test
  62.  
  63. call ReadArgs("test=on", "test/T")
  64. say test
  65.  
  66. drop test
  67. call ReadArgs("test=on", "test/T", "args.")
  68. say args.test
  69.  
  70. /*--- test for /M ---*/
  71. template = "name/M,test/S"
  72. input = "ich du er sie es test"
  73.  
  74. if ReadArgs(input,template) then do
  75.   say name.count test
  76.   do i = 0 for name.count by 1
  77.     say name.i
  78.   end
  79. end
  80.  
  81. say; Say "test pattern matching:"
  82. pattern = "ha*mut"
  83. string = "hartmut"
  84.  
  85. say MatchPattern(pattern,string);
  86.  
  87. string = Upper(string)
  88. say MatchPattern(pattern,string);
  89. say MatchPattern(pattern,string,"N");
  90.  
  91. string = "hartmut"
  92. pattern = parsePattern(string)
  93. say rc
  94. pattern = ParsePattern("ha*mut")
  95. say MatchPattern(pattern,string,,"P");
  96. string = Upper(string)
  97. say MatchPattern(pattern,string,,"P");
  98. pattern = ParsePattern("har*ut","N")
  99. say MatchPattern(pattern,string,"N","P");
  100.  
  101.  
  102. say; say "last but not least: environment variables"
  103. call MyGetVar("foobar")
  104.  
  105. /* PLEASE NOTE: local varibales do not work as exspected since ARexx
  106.  * creates a new process for each script. Thus there is no way to
  107.  * access the shell env-vars. Sorry!
  108.  * But you may pass local env-vars to programms started from a skript.
  109.  * See below for example (address command 'get foobar').
  110.  */
  111.  
  112. SetVar("foobar", "Oh, wunderfull, this is a local environment variable", "L")
  113. call MyGetVar("foobar")
  114. call MyGetVar("foobar","L")
  115. call MyGetVar("foobar","G")
  116.  
  117. /* some tests for passing local vars to a shell */
  118. say;say "Now we try to access local vars <address command 'get foobar'> ..."
  119. address command 'get foobar'
  120. say "... and set local vars <address command 'get foobar ""blafasel""'>"
  121. address command 'set foobar "blafasel"'
  122. call MyGetVar("foobar","L")
  123.  
  124. /* TestVars.rexx
  125. ...8<--- TestVars.rexx ---
  126.    result = GetVar("foobar","L")
  127.    IF rc = 0 THEN say "L: foobar has value <"result">";
  128.           else say "L: foobar not set"
  129.    SetVar("foobar", "variable changed", "L")
  130. ...8<---
  131. call MyGetVar("foobar","L")
  132. */
  133.  
  134. say DeleteVar("foobar", "L")
  135.  
  136. say; say "Presentation finished"; say "Good bye!"
  137.  
  138. exit 0
  139.  
  140. /* --- support routines --- */
  141.  
  142. TestAddPart: PROCEDURE
  143.   dir = arg(1); file = arg(2); path = AddPart(dir,file)
  144.   if RC = 0 then
  145.     say dir '+' file '->' path
  146.   else
  147.     say dir '+' file '**failed**'
  148. return
  149.  
  150. MyGetVar: PROCEDURE
  151.   name = arg(1)
  152.   if arg(2,'ommited') then do
  153.     result = GetVar(name)
  154.     state = ""
  155.   end; else do
  156.     result = GetVar(name,arg(2))
  157.     state = arg(2)': '
  158.   end
  159.   IF rc = 0 THEN say state'foobar has value <"result">';
  160.             else say state'foobar not set'
  161. return 0
  162.